﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FCTC_Web.Models;
using DAL;
using FCTC_Web.Utilities;

namespace FCTC_Web.Controllers.Business.BusinessModel
{
    public class EstimatorDetailBusiness : BusinessBase
    {
        public EstimatorDetailBusiness(int? i)
        {
            Estimator = CH.GetDataById<Estimator>(i);

            if (Estimator == null)
                throw new Exception("该评估师不存在");

            OwnerShop = CH.GetDataById<Shop>(Estimator.ShopID);
            EstimatorRecommandedVehicle = CH.GetAllData<Vehicle>().FindAll(c => c.EstimatorID == i && c.VehicleStatus=="热卖");
        }

        public List<Vehicle> EstimatorRecommandedVehicle{  get; set; }

        public Estimator Estimator { get; set; }

        public Shop OwnerShop { get; set; }
    }

    public class EstimatorBusiness
    {
        public static EstimatorBusiness _ins = new EstimatorBusiness();
        public static EstimatorBusiness Ins
        {
            get { return _ins; }
        }


        public List<Estimator> EstimatorList
        {
            get { return CH.GetAllData<Estimator>().OrderByDescending(i=>i.Sequense).ToList(); }
        }

        public Page<Estimator> EstimatorPage
        {
            get;
            set;
        }

        public List<Estimator> RecommendedEstimator
        {
            get
            {
                var estimators = CH.GetAllData<Estimator>();
                if (estimators.Count > 2)
                    return estimators.GetRange(0, 2).OrderByDescending(i => i.Sequense).ToList();
                else
                    return estimators;
            }
        }

        public Banners Banners
        {
            get { return Banners.Ins; }
        }
    }
}